package customerController

import (
	"WEB/models"
	"fmt"
	"github.com/astaxie/beego"
)

type BaseController struct {
	beego.Controller
}

func (this *BaseController) Prepare() {
	s := this.Ctx.Request.RequestURI
	isLogin := this.GetSession("isLogin")
	username := this.GetSession("Username")
	user := this.GetSession("User")
	if isLogin == "true" {
		this.Data["Username"] = username
		temp := user.(models.User)
		this.Data["Address"] = fmt.Sprintf("%s %s %s %s", temp.UserProvince, temp.UserCity, temp.UserArea, temp.UserAddress)
		return
	}

	if s == "/customer/login" || s == "/customer/register" || s == "/customer/error" || s == "/customer/index" || s == "/" {
		return
	} else {
		this.Redirect("/customer/login", 302)
	}
}
